package ast;

/*
 *  Expresion asociado al commando de asignacion a una variable.
 *  Nodo del arbol semantico.
 */

public class ExpAsigVar implements Expresion  {

	/**
	 * ATTRIBUTES
	 */
	// id de la variable a asignar
	private int _IdVar;
	
	/**
	 * Constructor
	 */
	public ExpAsigVar( int pIdVar ){
		_IdVar = pIdVar;
	}
	
	/**
	 * Codigo asociado a esta expresion
	 */
	@Override
	public String GenerarCodigo() {
		String code = new String();
		String strVar = String.valueOf(_IdVar);
		code += ConstCode.VAR + strVar + ConstCode.ASIG_SUMA + ConstCode.FLUJO + ConstCode.FIN_LINE;
		code += ConstCode.IF_EXP + ConstCode.VAR + strVar + ConstCode.MAYOR + ConstCode.MAX + ConstCode.END_IF_EXP;
		code += ConstCode.FLUJO +  ConstCode.ASIG + ConstCode.VAR + strVar + ConstCode.RESTA + ConstCode.MAX + ConstCode.FIN_LINE;
		code += ConstCode.VAR + strVar + ConstCode.ASIG_RESTA + ConstCode.FLUJO + ConstCode.FIN_LINE;
		code += ConstCode.ELSE;
		code += ConstCode.FLUJO +  ConstCode.ASIG + ConstCode.CERO + ConstCode.FIN_LINE;
		code += ConstCode.END_CORCHET;
		
		/*
		var_Id 	+= flujo;
		flujo 	= var_Id � MAX;
		var_Id 	-= flujo;
		*/
		return code;		
	}

}
